package com.tvata.smarttv.ktv.aiopen;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.text.TextUtils;

import com.vatata.tools.res.StringUtils;

import java.util.List;

public class AIOpenUtils {

    public static void registerKaraokeApp(Context context) {
        Intent localIntent = new Intent();
        localIntent.setAction(AIOpenConstant.AI_OPEN_ACTION_APP_REGISTER);
        Bundle data = new Bundle();
        data.putString("package_name", context.getPackageName());
        data.putLong("category", AIOpenConstant.SEMANTIC_KTV);
        localIntent.putExtras(data);
        localIntent.setPackage("com.peasun.aispeechgl");//gl
        //context.sendBroadcast(localIntent, AIOpenConstant.AI_OPEN_ACTION_PERMISSION);
        context.sendBroadcast(localIntent);
    }

    public static AIOpenReceiver registerKaraokeReceiver(Context context) {
        AIOpenReceiver receiver = new AIOpenReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction(AIOpenConstant.AI_OPEN_ACTION_KTV);
        //context.registerReceiver(receiver, filter, AIOpenConstant.AI_OPEN_ACTION_PERMISSION, null);
        context.registerReceiver(receiver, filter);
        return receiver;
    }

    public static boolean isForeground(Context context, String className){
        if(context == null || TextUtils.isEmpty(className)){
            return false;
        }
        ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningTaskInfo> list = am.getRunningTasks(1);
        if(list != null && list.size() > 0){
            ComponentName cpn = list.get(0).topActivity;
            if(className.equals(cpn.getClassName())){
                return true;
            }
        }
        return false;
    }
}
